#include "MyView.h"
#include "MapEngine.h"
#include <QWheelEvent>
#include <QRectF>

MyView::MyView(MapStatus* status)
: m_pMapStatus(NULL), m_pMapEngine(NULL)

{
	m_pMapStatus = status;
	m_dCurrentLevel = m_pMapStatus->Map_Level;

}

MyView::~MyView()
{
	if (m_pMapEngine!=NULL)
	{
		delete m_pMapEngine;
		m_pMapEngine = NULL;
	}
}

void MyView::wheelEvent(QWheelEvent * event)
{
	
	if (event->delta() > 0)
	{
		if (m_pMapStatus->Map_Level<21)
		{
			m_pMapStatus->Map_Level += ScaleChange;
		}
	}
	if (event->delta() < 0)
	{
		if (m_pMapStatus->Map_Level>0)
		{
			m_pMapStatus->Map_Level = m_pMapStatus->Map_Level - ScaleChange;
		}
	}
	int level = m_pMapStatus->Map_Level;

	if (m_pMapEngine != NULL)
	{
		m_pMapEngine->wheelEvent(event);
	}
}

void MyView::mousePressEvent(QMouseEvent * event)
{
	QGraphicsView::mousePressEvent(event);
	if (m_pMapEngine != NULL)
	{
		m_pMapEngine->mousePressEvent(event);
	}
}

void MyView::mouseMoveEvent(QMouseEvent * event)
{
	QGraphicsView::mouseMoveEvent(event);
	if (m_pMapEngine!=NULL)
	{
		m_pMapEngine->MouseMove(event);
	}
}

void MyView::mouseReleaseEvent(QMouseEvent * event)
{
	if (m_pMapEngine != NULL)
	{
		m_pMapEngine->mouseReleaseEvent(event);
	}
}

void MyView::drawBackground(QPainter * painter, const QRectF & rect)
{
}

void MyView::setScene(QGraphicsScene *scene)
{
	QGraphicsView::setScene(scene);
	m_pMyScene = scene;


	if (m_pMyScene&&m_pMapStatus)
	{
		m_pMapEngine = new MapEngine(m_pMyScene, m_pMapStatus, this);
	}
	
}

void MyView::ShowImage()
{
	
	if (m_pMapEngine)
	{
	  m_pMapEngine->ShowImage();
	}
	
}

void MyView::ShowImageWithoutNotes()
{
	if (m_pMapEngine)
	{
		m_pMapEngine->ShowImageWithoutNotes();
	}
}

void MyView::ShowVectorTile()
{
	if (m_pMapEngine)
	{
		m_pMapEngine->ShowVectorTile();
	}
}

void MyView::ShowTerrian()
{
	if (m_pMapEngine)
	{
		m_pMapEngine->ShowTerrian();
	}
}

void MyView::ShowTerrianWithoutNotes()
{
	if (m_pMapEngine)
	{
		m_pMapEngine->ShowTerrianWithoutNotes();
	}
}

void MyView::UpdateMap()
{
	if (m_pMapEngine != NULL)
	{
		m_pMapEngine->UpdateMap();
	}
}

